﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AspNetCs.Model;
using AspNetCs.Bll;
using System.Data;
using System.Collections;
using AspNetCs.Enumerations;
using AspNetCs.Enumerations.memorial_enum;
using AspNetCs.Enumerations.User_Enum;
using AspNetCs.Common;
using AspNetCs.Enumerations.Channel_Enum;


public partial class Users_AncestralHallList : BasePage
{
    private AncestralHallBLL bll = new AncestralHallBLL();
    protected void Page_Load(object sender, EventArgs e)
    {
        CheckUserExit("Login.Aspx?ReUrl=" + configInfo.InstallDir + "Users/AncestralHallList.aspx", "请您登录", true);
        if (!IsPostBack)
        {
            getMyCreateAncestralHalls();
        }
    }


    private void getMyCreateAncestralHalls()
    {
        Users_Model userModel = Base_GetUserInfo;
        string propertyItems = "id,AncestralHallId,Name,PreName,CreateTime";
        DataTable dataTable = bll.getMyCreateAncestralHallItems(userModel.UserId, propertyItems, 0);
        rptAnestralHallList.DataSource = dataTable;
        rptAnestralHallList.DataBind();
    }

    private bool deleteAncestralHall(int id)
    {
        int count = 0;
        count = bll.Delete(id);

        int count1 = 0;

        //删除宗祠论坛
        AncestralHallBBSBLL bbsBLL = new AncestralHallBBSBLL();
        count1 = bbsBLL.Delete(id);

        int count2 = 0;

        //删除宗祠版块
        AncestralHallItemsBLL itemsBLL = new AncestralHallItemsBLL();
        count2 = itemsBLL.Delete(id);

        return (count > 0 && count1 > 0 && count2 > 0) ? true : false;
    }

    protected void rptAnestralHallList_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        bool bo = false;
        //Response.Write("<script>alert('"+btnDelete.CommandArgument+"');</script>");
        if (e.CommandName == "delete")
        {
            LinkButton btnDelete = e.Item.FindControl("btnDelete") as LinkButton;
            if (btnDelete != null)
            {
                string id = btnDelete.CommandArgument;
                try
                {
                    bo = deleteAncestralHall(Convert.ToInt32(id));
                }
                catch (Exception ex)
                {
                    bo = false;
                }
            }
        }
        if (e.CommandName == "CreateHtml")
        {

            AncestralHall_Model HTMLmd = AncestralHall_Bll.CreatNew.GetModel(StringHelper.isNumber_int(e.CommandArgument.ToString()));
            string NumUrl = HTMLmd.AncestralHallId + ".html";

            string CreateHtmlUrl = configInfo.InstallDir + "Html/" + Channel_Type.clan.ToString() + "/" + NumUrl;
            TempleBll.CreateNew.TempleCreate(Server.MapPath(CreateHtmlUrl), NumUrl, Channel_Type.clan, true);
            Response.Write("<script>alert('生成成功！');location.href='AncestralHallList.aspx';</script>");
            Response.End();

        }
        if (e.CommandName == "manage")
        {
            LinkButton btnManage = e.Item.FindControl("btnManage") as LinkButton;
            if (btnManage != null)
            {
                string id = btnManage.CommandArgument;
                try
                {
                    Response.Redirect("UpdateAncestralHall_" + Convert.ToInt32(id) + ".aspx");
                }
                catch (Exception ex)
                {
                }
            }
        }
        getMyCreateAncestralHalls();
    }
}
